package com.wing.unit.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.unit.dao.AgentLevelDao;
import com.wing.unit.model.entity.AgentLevel;
import com.wing.unit.model.request.AgentLevelForm;
import com.wing.unit.model.response.AgentLevelVO;
import com.wing.web.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 代理商级别表-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class AgentLevelServiceImpl extends ServiceImpl<AgentLevelDao, AgentLevel> implements AgentLevelService {

    @Override
    public int add(AgentLevelForm agentLevelForm) {
        //校验
        AgentLevel agentLevel =new AgentLevel();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(AgentLevel.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(agentLevelForm, agentLevel, copyOptions);
        agentLevel.setCreatorName(JwtUtils.getLoginUsername());
        return baseMapper.insert(agentLevel);
    }

    @Override
    public List<AgentLevelVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<AgentLevelVO> pageList4app(Page page, Map<String, Object> params) {
        List<AgentLevelVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public AgentLevelVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }
}
